package hutool.qrcode;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * hutool二维码简单案例
 */
public class QrCode {

    public static void main(String[] args) throws IOException {
        QrConfig config = new QrConfig();
        // 高纠错级别
        config.setErrorCorrection(ErrorCorrectionLevel.H); //纠错级别高
        config.setImg(ImgUtil.read(new URL("网络图片"))); //附带中心logo
        config.setRatio(4); //logo缩放比例
        StringBuilder builder = new StringBuilder();
        builder.append("https://gitee.com/yezhiqiu521"); //URL地址

        BufferedImage bufferedImage = QrCodeUtil.generate(builder.toString(), config);
        String datauri = ImgUtil.toBase64DataUri(bufferedImage, "png"); //返回datauri

        File file = FileUtil.file("C:\\Users\\admin\\Desktop\\qrcode.jpg"); ////写出到的文件
        QrCodeUtil.generate(builder.toString(), config, FileUtil.file(file));
    }
}
